package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Pet;
import com.example.springboot.service.PetService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//标记Controller类
@RestController
@RequestMapping("/pet")
public class PetController {
    @Resource
    PetService petService;
    //RequestMapping映射
@GetMapping("/selectAll")
    public Result selectAll(){
    List<Pet> list = petService.selectAll();
    return Result.success(list);
}
    /**
     * 描述：分页查询
     */
    @GetMapping("/selectPage")
    public Result page(Pet pet,
                       @RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "5") Integer pageSize) {
      PageInfo<Pet> pageInfo=   petService.selectPage(pet, pageNum, pageSize);
        return Result.success(pageInfo);
    }
    @PostMapping("/save")
    public Result save(@RequestBody Pet pet){

        petService.savePet(pet);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        petService.deleteById(id);
        return Result.success();
    }
    @PostMapping("/update")
    public Result updateById(@RequestBody Pet pet) {
        petService.updateById(pet);
        return Result.success();
    }

}
